package com.task.job.system;

import java.util.List;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.entity.Recharge;
import com.interfaces.RechargeDao;
import com.task.job.recharge.CloseJob;
import com.task.job.recharge.OpenJob;
import com.task.job.recharge.RechargeJob;
import com.task.job.recharge.RefundJob;
import com.task.manage.JobManage;

@Component
public class GetRecharge implements Job {

	@Autowired
	private RechargeDao rechargeDao;
	@Autowired
	private JobManage jobManage;

	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		/**
		 * 获取任务信息
		 */

		// 查询所有的工单信息
		List<Recharge> recharges = rechargeDao.findByOptstatusGroupByMeterid();
		// 根据工单信息，启动费控job
		Job job = null;
		for (Recharge recharge : recharges) {
			if (recharge.getOptstatus().equals("等待下发")) {
				// 启动下发任务
				switch (recharge.getDirection()) {
				case "购电":
					switch (recharge.getFrequency()) {
					case 0:
						job = new OpenJob();
						break;	
					default:
						job = new RechargeJob();
						break;
					}
					break;
				case "退费":
					job = new RefundJob();
					break;
				case "销户":
					job = new CloseJob();
					break;
				default:
					break;
				}
			}
			if (job != null) {
				jobManage.addjobforone(String.valueOf(recharge.getRechargeid()), job,
						"recharge" + recharge.getRechargeid(), "recharge", "");
			}

		}

	}

}
